/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 * @author BENSON
 */

public class ControllerBookAppointment {
    /**
    * variable and views declarations
    */
    Views.BookAppointment bookAppoint;
    Model.MainModel model;
    private ActionListener actionListener;
    
    
    /**
     * Default constructor for instantiating declared objects
     * @param x
     * @param y
     */
    public ControllerBookAppointment(String x,String y ){
        bookAppoint = new Views.BookAppointment();
        bookAppoint.setVisible(true);
        bookAppoint.getPatientNum().setText(x);
        bookAppoint.getPatientName().setText(y);
        model= new Model.MainModel();
    } 
   
     /**
      * Method to get source of button clicked using action listener
      */
    
     public void control(){        
        actionListener = new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent actionEvent) {  
                  if(actionEvent.getSource()==bookAppoint.getSaveBtn()){
                        model.addAppointments(bookAppoint);
                  }
                  if(actionEvent.getSource()==bookAppoint.getCloseBtn()){
                  bookAppoint.setVisible(false);
                  
                  }
               }
              
        };                
        bookAppoint.getSaveBtn().addActionListener(actionListener);
        bookAppoint.getCloseBtn().addActionListener(actionListener);
        
    }
    
}
